<template>
  <el-dialog
    title="分配角色"
    width="500px"
    :visible="isShow"
    @close="cancelEvent"
  >
    <!--
      el-checkbox-group  v-model=“非数组（一定是一个boolean值）数组（选中某项就相当于数组中添加该项的值）”
      label:选中该项后的值
         <el-checkbox    label:选中该项后的值 >内容</el-checkbox>
         <el-checkbox   >内容</el-checkbox>

   -->
    <!-- <h1>{{ value }}</h1> -->
    <el-checkbox-group v-model="value">
      <el-checkbox v-for="item in list" :key="item.id" :label="item.id">{{
        item.name
      }}</el-checkbox>
    </el-checkbox-group>

    <template #footer>
      <div style="text-align: center">
        <el-button type="primary" @click="submit">提交</el-button>
        <el-button @click="cancelEvent">取消</el-button>
      </div>
    </template>
  </el-dialog>
</template>
<script>
import { sysRole } from '@/api/setting.js'
import { sysUser } from '@/api/user.js'
import { sysUserAssignRoles } from '@/api/employees.js'
export default {
  props: {
    isShow: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      list: [],
      value: [],
      id: ''
    }
  },
  created() {
    this.getData()
  },
  methods: {
    //   关闭弹框
    cancelEvent() {
      this.$emit('update:isShow', false)
      this.value = []
    },
    // 获取所有角色列表
    async getData() {
      const res = await sysRole({
        page: 1,
        pagesize: 1000
      })
      this.list = res.data.rows
      console.log('角色列表数据', res)
    },
    // 获取当前打开帐号的详情信息包括角色
    async getUserInfo(id) {
      this.id = id
      //   获取用户详情包括角色信息
      const res = await sysUser(id)
      //   赋值当前用户角色信息到复选框组件用于回显
      this.value = res.data.roleIds
      console.log('用户详情', res)
    },
    // 提交点击
    async submit() {
      await sysUserAssignRoles(this.id, this.value)
      this.cancelEvent()
      this.$message.success('修改成功')
    }
  }
}
</script>
<style></style>
